function auto_tag();
%
% Automatically tag data for analysis.
% Example routine (modify as needed.)
%
% For each of the unique filenames in the database, this one finds
% the protocol ipsp_noise_frozen
% and if the Experimental Condition flag (E_C) is empty, it does the
% following:
%
% select the entry
%    change the entry so that the record list is 1st-end/3
%     set E_C to I
% duplicate the entry
%    change the entry so that the record list is 1st+1-end/3
%    set E_C to N
% duplicate the entry again
%    change the entry so that the record list is 1st+2-end/3
%    set E_C to E
%
%

global CONTROL

testflag = 0; % verify the run before commiting

s= unique({CONTROL(:).filename});
proto = 'ipsp-noise-frozen';
p = strfind({CONTROL(:).protocol}, proto);

for i = 1:length(p)
    fprintf(1, 'checking: %s  %d\n', CONTROL(i).filename, CONTROL(i).recbeg);
    if(isempty(p{i})) continue; end;
    j = strmatch(s, CONTROL(i).filename);
    if(~isempty(strfind('INE', CONTROL(i).E_C)) || ~strncmp(CONTROL(i).E_C, '[]', 2))
        fprintf(1, 'File %d  %s already done; E_C = %s   reclist = %s\n', ...
            i, CONTROL(i).filename, CONTROL(i).E_C, CONTROL(i).reclist);
        continue;
    end;
    rl = CONTROL(i).reclist;
    rl = sprintf('%d;%d/3', CONTROL(i).recbeg, CONTROL(i).recend); % select by thirds.
    ec = 'I';
    if(~testflag)
        CONTROL(i).reclist = rl;
        CONTROL(i).E_C = ec;
    end;
    if(testflag)
        fprintf(1, 'File %s becomes: E_C = %s   reclist = %s\n', ...
            CONTROL(i).filename, ec, rl);
    end;

    rl = CONTROL(i).reclist;
    rl = sprintf('%d;%d/3', CONTROL(i).recbeg+1, CONTROL(i).recend); % select by thirds.
    ec = 'N';
    if(~testflag)
        l = length(CONTROL);
        CONTROL(l+1) = CONTROL(i);% duplicate
        CONTROL(l+1).reclist = rl;
        CONTROL(l+1).E_C = ec;
    end;
    if(testflag)
        fprintf(1, 'File %s becomes: E_C = %s   reclist = %s\n', ...
            CONTROL(i).filename, ec, rl);
    end;
    rl = CONTROL(i).reclist;
    rl = sprintf('%d;%d/3', CONTROL(i).recbeg+2, CONTROL(i).recend); % select by thirds.
    ec = 'E';
    if(~testflag)
        l = length(CONTROL);
        CONTROL(l+1) = CONTROL(i);% duplicate
        CONTROL(l+1).reclist = rl;
        CONTROL(l+1).E_C = ec;
    end;
    if(testflag)
        fprintf(1, 'File %s becomes: E_C = %s   reclist = %s\n', ...
            CONTROL(i).filename, ec, rl);
    end;


end;

